/*
* berton
*/
package com.pitop.t.ctrl;

import com.alibaba.fastjson.JSON;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.t.entity.Role;
import com.pitop.t.service.TroleSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
*  控制器
*
* @author berton
*/
@RestController
@RequestMapping("/trole")
@Slf4j
@Api(value = "控制器", description = "控制器")
public class TroleCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private TroleSV troleSV;

    /**
    * 查询Trole一个详情信息
    * @param roleId 
    * @return BeanRet
    */
    @ApiOperation(value = "查询Trole一个详情信息", notes = "查询Trole一个详情信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "roleId", value = "",dataType = "java.lang.Integer", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public Role load(java.lang.Integer roleId) {
        if(roleId==null){
        return null;
        }
        Role trole = troleSV.load(roleId);
        log.info(JSON.toJSONString(trole));
        return trole;
    }


    /**
    * 根据条件roleId查询Trole一个详情信息
    *
    * @param roleId 
    * @return BeanRet
    */
    @ApiOperation(value = "查询Trole一个详情信息", notes = "查询Trole一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "roleId", value = "",dataType = "java.lang.Integer", paramType = "path")
    })
    @GetMapping(value = "/load/roleId/{roleId}")
    @ResponseBody
    public Role loadByRoleId(@PathVariable java.lang.Integer roleId) {
        if(roleId==null){
           return null;
        }
        Role trole = troleSV.loadByRoleId(roleId);
        log.info(JSON.toJSONString(trole));
        return trole;
    }


    /**
    * 查询Trole信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询Trole信息集合", notes = "查询Trole信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<Role> list( @ApiIgnore Role trole, Integer curPage, Integer pageSize) {
        Page<Role> page=new Page<Role>(pageSize,curPage);
        List<Role> troles = troleSV.list(trole,page.genRowStart(),page.getPageSize());
        int total = troleSV.count(trole);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return troles;
    }





    /**
    * 创建Trole
    *
    * @return BeanRet
    */
    @ApiOperation(value = "创建Trole", notes = "创建Trole")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "name", value = "角色名称", paramType = "query"),
    @ApiImplicitParam(name = "descr", value = "角色说明", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public Role build( @ApiIgnore Role trole) {
        troleSV.save(trole);
        return trole;
    }


    /**
    * 修改Trole
    *
    * @return BeanRet
    */
    @ApiOperation(value = "修改Trole", notes = "修改Trole")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "roleId", value = "", paramType = "query"),
        @ApiImplicitParam(name = "name", value = "角色名称", paramType = "query"),
        @ApiImplicitParam(name = "descr", value = "角色说明", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public Role modify(@ApiIgnore Role trole) {
        troleSV.modify(trole);
        return trole;
    }


}
